package com.mao.model.organization;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.apache.struts2.json.annotations.JSON;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Where;

import com.mao.model.common.ClassBase;

@Entity
@Table(name = "MAO_ORGANIZATIONCLASS")
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
public class OrganizationClass extends ClassBase {

	private static final long serialVersionUID = 1L;
	private OrganizationClass parent; // 上级分类
	private Set<OrganizationClass> lowClass;

	@ManyToOne(optional = true, fetch = FetchType.LAZY)
	@JoinColumn(name = "PARENT_ID", nullable = true)
	@JSON(serialize = false)
	public OrganizationClass getParent() {
		return parent;
	}

	public void setParent(OrganizationClass parent) {
		this.parent = parent;
	}

	@OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "parent")
	@BatchSize(size = 50)
	@Where(clause = "status=" + STATUS_NORMAL)
	@OrderBy("sortNo asc")
	@JSON(serialize = false)
	public Set<OrganizationClass> getLowClass() {
		return lowClass;
	}

	public void setLowClass(Set<OrganizationClass> lowClass) {
		this.lowClass = lowClass;
	}

}
